import { PROCESS_TYPES, MODE } from '@/constants/ttsa'
import { useTtsaStore } from '@/store/ttsa'

export default function useController() {
  const ttsaStore = useTtsaStore()

  // 播放/暂停
  const onHandPaused = () => {
    ttsaStore?.paused ? (ttsaStore?.process === PROCESS_TYPES.idle_response ? ttsaStore.next() : ttsaStore.goon()) : ttsaStore.pause()
  }

  // 提问/讲解
  const onHandQa = () => {
    ttsaStore[ttsaStore.mode === MODE.QA ? 'qaToExplain' : 'explainToQa']()
  }

  // 提问
  const onChart = (content) => ttsaStore.chat(content)

  // 语音/文本
  const asrType = ref(true)
  const onHandAsr = () => {
    asrType.value = !asrType.value
  }

  // 输入框显示
  const inputVisible = ref(false)


  provide('asrType', asrType)
  provide('inputVisible', inputVisible)

  return {
    ttsaStore,
    onHandPaused,
    onHandQa,
    onChart,
    onHandAsr,
    asrType,
    inputVisible
  }
}

